home *** CD-ROM | disk | FTP | other *** search
- Grammar Layout
- Previous: <Stages=>Stages> * Next: <Examples=>Examples> * Up: <Concepts=>Concepts>
-
- #Wrap on
- {fH3}The Overall Layout of a Bison Grammar{f}
-
- The input file for the Bison utility is a {fUnderline}Bison grammar file{f}. The
- general form of a Bison grammar file is as follows:
-
- #Wrap off
- #fCode
- %\{
- {fStrong}C declarations{f}
- %\}
-
- {fStrong}Bison declarations{f}
-
- %%
- {fStrong}Grammar rules{f}
- %%
- {fStrong}Additional C code{f}
- #f
- #Wrap on
-
- The {fEmphasis}%%{f}, {fEmphasis}%\{{f} and {fEmphasis}%\}{f} are punctuation that appears
- in every Bison grammar file to separate the sections.
-
- The C declarations may define types and variables used in the actions.
- You can also use preprocessor commands to define macros used there, and use
- {fCode}\#include{f} to include header files that do any of these things.
-
- The Bison declarations declare the names of the terminal and nonterminal
- symbols, and may also describe operator precedence and the data types of
- semantic values of various symbols.
-
- The grammar rules define how to construct each nonterminal symbol from its
- parts.
-
- The additional C code can contain any C code you want to use. Often the
- definition of the lexical analyzer {fCode}yylex{f} goes here, plus subroutines
- called by the actions in the grammar rules. In a simple program, all the
- rest of the program can go here.
-
-